package com.wn.factoryUtils;

import com.wn.entity.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class LastBeanFactory {
    static Map<Object,Object> map = new HashMap<>();
    static {
        Properties properties = new Properties();
        InputStream resourceAsStream = LastBeanFactory.class.getResourceAsStream("application.properties");
        String PersonName = "";
        try {
            properties.load(resourceAsStream);
            Set<Object> keys = properties.keySet();
            for (Object key: keys) {
                PersonName = properties.getProperty(key+"");
                Class<?> aClass = Class.forName(PersonName);
                Object o = aClass.newInstance();

                map.put(key,o);

            }
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    public Person getBean(String name){
        Person person =(Person) map.get(name);
        return person;
    }
}
